$(document).ready( function () {
	$('html').removeClass('no-js');	
	$('#navigation ul li').each( function () {
		if($(this).children('ul').length > 0) {
			$(this).addClass('hasChildren');
		}	
	});	
	$('#navigation ul ul').fadeTo(0, 0);
	$('#navigation ul ul').css('display', 'none');
	$('#navigation ul > li').each( function () {
		if($(this).children('ul').length > 0) {
			$(this).bind('mouseenter', function () {
				$(this).children('ul').css('display', 'block');
				$(this).children('ul').fadeTo('fast', 1);
			});
			$(this).bind('mouseleave', function () {
				$(this).children('ul').fadeTo('fast', 0);		
				$(this).children('ul').css('display', 'none');
			});		
		}
	});
	
	if ($.browser.msie) {
		$('#navigation li').bind('mouseenter', function () {
			$(this).addClass('over');
		});
		$('#navigation li').bind('mouseleave', function () {
			$(this).removeClass('over');
		});
		$('#navigation ul li ul li').each( function () {
			if ($(this).is(':first-child')) {
				$(this).addClass('firstchild');
			} else if ($(this).is(':last-child')) {
				$(this).addClass('lastchild');
			}
		});
	}	
	
	$('#content .segments .segment:nth-child(even), .left_segments .segment:nth-child(even)').addClass('even');
	$('#content .segments .segment table td:last-child, .left_segments .segment table td:last-child').addClass('last-child');

	$('#content .collapsible').not('.open').each(function () {
		var collapsible = $(this);
		collapsible.children('h3').click(function() {
			var currHeight = collapsible.height();
			collapsible.children('.showhide').toggle();

			if (!collapsible.hasClass('open')) {
				collapsible.addClass('open');
				if (collapsible.find('form').length > 0) {
					collapsible.find('input[type=text]')[0].focus();
				}
			} else {
				collapsible.removeClass('open');
			}
			
		});
	});

	$('#content .collapsible.open').each(function () {
		var collapsible = $(this);
		collapsible.children('.showhide').toggle();
	});
	
	$('#content .collapsible h3').each(function() {$(this).click();});

	$('.form').each( function () {
		var form = $(this);
		var widestLabel = 0;
		form.find('label:first-child, .labelSpacer').each( function () {
			var label = $(this);
			if (label.width() > widestLabel) {
				widestLabel = label.width();
			}
			var labelfor = label.attr('for');
			if ($('#' + labelfor).is('textarea')) {
				label.css('vertical-align', 'top');
			}
		});
		form.find('label:first-child, .labelSpacer').width(widestLabel);
	});

	$('#content .collapsible h3').each(function() {$(this).click();});

	$('.dp_email').jantiscrape({ user: 'dataprotection', domain: 'wolf-software.com' });
	$('.job_email').jantiscrape({ user: 'careers', domain: 'wolf-software.com' });
	$('.gen_email').jantiscrape({ user: 'enquiries', domain: 'wolf-software.com' });
	$('.ceo_email').jantiscrape({ user: 'tim.gurney', domain: 'wolf-software.com' });

        $('.boxquote').each( function () {
                var openImg = $('<img src="/assets/images/quoteopen.png" class="open" />');
                var closeImg = $('<img src="/assets/images/quoteclose.png" class="close" />');
                $(this).append(openImg);
                $(this).append(closeImg);
        });

	$('label.infield').inFieldLabels({fadeOpacity: 0, fadeDuration: 0});

	$.jpecrga({ gaKey: 'UA-22333772-1' });	
});

